package com.woniuxy.utils;

// SensitiveWordFilter.java
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

public class SensitiveWordFilter {
    // 敏感词库（简化示例，实际可从数据库或文件加载）
    private static final Set<String> SENSITIVE_WORDS = new HashSet<>(Arrays.asList(
            "微信", "QQ", "日本鬼子"
    ));

    // 替换字符
    private static final char REPLACE_CHAR = '*';

    /**
     * 过滤敏感词
     */
    public static String filter(String text) {
        if (text == null || text.isEmpty()) return text;

        for (String word : SENSITIVE_WORDS) {
            if (text.contains(word)) {
                // 替换为等长的*
                String replaceStr = String.valueOf(REPLACE_CHAR).repeat(word.length());
                text = text.replace(word, replaceStr);
            }
        }
        return text;
    }
}